<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\TiebaRequest;
use App\Models\Tieba;
use App\Models\User;
use App\Handlers\DownHtmlHandler;
use App\Handlers\SubjectHandler;

class TiebaController extends Controller
{
    public function __construct()
    {
    	$this->middleware('auth');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(DownHtmlHandler $down, Tieba $tieba)
    {
        $html = new SubjectHandler('/2018/0928/subject/5890455639.html');
        //dd($html->getSubjectUrl('LOL/2018/0927/index/1538050432.html'));
        print_r($html->floor());
    }

    public function subject(Request $request, DownHtmlHandler $down)
    {
        $tid = $request->tid;
        // $filename = $down->getSubject($tid);
        $info = new SubjectHandler('/2018/0928/subject/' . $tid . '.html');
        print_r($info->floor());
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create(Tieba $tieba, User $user)
    {
        $this->authorize('create', $tieba);
        
        return view('tieba.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(TiebaRequest $request, Tieba $tieba)
    {
        $this->authorize('create', $tieba);
        $tieba->fill($request->all());
        $tieba->save();
        return redirect()->route('tieba.create', $tieba->id)->with('success', ' 添加成功！');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
